package xyz.riceball.springcloudstreamstudy;

import jakarta.annotation.Resource;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.riceball.springcloudstreambinderredis.common.Constants;

import java.time.LocalDateTime;

// @checkstyle:off

/**
 * Producer.
 *
 * @author xiaovcloud
 * @since 2024/6/12 10:50
 */
@RestController
public class Producer {

	@Resource
	private StreamBridge streamBridge;

	@RequestMapping("/normal")
	public void sendNormal(String msg) {
		Message<String> message = MessageBuilder.withPayload(msg)
			.setHeader("key1", "value1")
			//在请求上增加DELAY_MESSAGE参数即可开启延迟消息，单位ms
//			.setHeader(Constants.DELAY_MESSAGE, "5000")
			.build();
		streamBridge.send("myInput", message);
		System.out.println("消息已发送"+ LocalDateTime.now());
	}
}
// @checkstyle:on
